# --------------------------------------------------------------------------------------------------------------------
# Project:             Digital Payment System (DPS)
# Website:             http://code.google.com/p/dps-x509/
# Purpose of document: Exceptions for the project
# --------------------------------------------------------------------------------------------------------------------

# --------------------------------------------------------------------------------------------------------------------
class DPSBaseError(Exception):
  def __init__(self, what, info=""):
    self.__what_ = what
    self.__extraInfo_ = info
    
# --------------------------------------------------------------------------------------------------------------------
  def what(self):
    return self.__what_
  
# --------------------------------------------------------------------------------------------------------------------
  def extraInfo(self):
    return self.__extraInfo_

# --------------------------------------------------------------------------------------------------------------------
class DecodingError(DPSBaseError):
  """ generic decoding error. this should only be seen until a more accurate error can be created for the case. """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "DecodingError", info)

# --------------------------------------------------------------------------------------------------------------------
class InvalidSignatureError(DPSBaseError):
  """ signature does not match certificate """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "InvalidSignatureError", info)

# --------------------------------------------------------------------------------------------------------------------
class NoDataSuppliedError(DPSBaseError):
  """ No data is input into field """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "NoDataSuppliedError", info)
    
# --------------------------------------------------------------------------------------------------------------------
class MissingRequiredParametersError(DPSBaseError):
  """ Required fields are not present. Examples are token type, token value, exchanger... """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "MissingRequiredParametersError", info)
  
# --------------------------------------------------------------------------------------------------------------------
class InvalidParametersError(DPSBaseError):
  """ Parameters are not able to be handled by the system """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "InvalidParametersError", info)
    
# --------------------------------------------------------------------------------------------------------------------
class PKIMethodNotSupportedError(DPSBaseError):
  """ Dps does not support certificates that use pki methods other than RSA. 
  The certificate may be in fact be valid but is unsupported by our system. """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "PKIMethodNotSupportedError", info)    
    
# --------------------------------------------------------------------------------------------------------------------
class SignatureAlgorithmNotSupportedError(DPSBaseError):
  """ Dps does not support certificates that are hashed with anything other than SHA1. 
      The certificate may in fact be valid but is unsupported by our system. """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "SignatureAlgorithmNotSupportedError", info)    
    
# --------------------------------------------------------------------------------------------------------------------
class IssuerPublicKeyNotFoundError(DPSBaseError):
  """ the issuer public key can not be found in either the certificate chain or the datastore """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "IssuerPublicKeyNotFoundError", info)  

# --------------------------------------------------------------------------------------------------------------------
class DoubleSpendError(DPSBaseError):
  """ the certificate has already been reallocated """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "DoubleSpendError", info)  
    
# --------------------------------------------------------------------------------------------------------------------
class CertificateAlreadyInRegistrarError(DPSBaseError):
  """ exact certificate is already in the registrar """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "CertificateAlreadyInRegistrarError", info)
    
# --------------------------------------------------------------------------------------------------------------------
class RsaPrivateKeySigningError(DPSBaseError):
  """ unable to sign a certificate with a private key """  
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "RsaPrivateKeySigningError", info)
    
# --------------------------------------------------------------------------------------------------------------------
class RsaPrivateKeyCreateError(DPSBaseError):
  """ unable to create a private key """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "RsaPrivateKeyCreateError", info)    

# --------------------------------------------------------------------------------------------------------------------
class CertificateNotSignedError(DPSBaseError):
  """ certificate is yet to be signed """  
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "CertificateNotSignedError", info)

# --------------------------------------------------------------------------------------------------------------------
class CertificateCreateErrorError(DPSBaseError):
  """ unable to generate a certificate """
  def __init__(self, info= ""):
    DPSBaseError.__init__(self, "CertificateCreateErrorError", info)  